/*********************************************************************************
Description: This is a main function file
Author: SA12226114(Xin Zhu), SA12226139(Dan Su)
Date: 2012-11 

Copyright (c) 2012-2022 School of Software Engineering of USTC, All rights reserved.

**********************************************************************************/



#include "dbclient.h"




/*****************************************************************
Function Name: main
Description:
Parameter:  

@argc: argument count
@argv: argument vector

Author: 
Date:  
******************************************************************/
int main(int argc, char** argv)
{
    int sockfd;
    char recvline[MAXLINE], sendline[CMDLINE_LEN];
    char test[10];
    struct sockaddr_in servaddr;

    /* check whether argument count is right */
    if(argc != 2)
    {
        printf("usage: ./client <ipaddress>\n");
        
        return 0;
    }
    
    util_menu();

    
    /* generate a new socket for client */
    sockfd = sw_create_socket(PF_INET, SOCK_STREAM, 0);
    
    /* initialize structure sockaddr_in with protocol family, port number, ip */
    sw_init_socket(&servaddr, sizeof(servaddr), argv[1]);
    
    /* connect server using socket id */
    if(!sw_connect(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr)))
        return;
    
    //sw_recv(sockfd, sendline, CMDLINE_LEN, 0);
    printf("before");
    /* receive command and send it to server. */
    while(1)
    {
        printf(">>>");
        //util_getcommandline(sendline, CMDLINE_LEN);

        //sw_send(sockfd, sendline, strlen(sendline), 0);

        //memset(sendline, 0, CMDLINE_LEN);
        sw_recv(sockfd, recvline, MAXLINE, 0);
        
        printf("%s \n", recvline);
    }

    sw_close(sockfd);

    return 0;
}
